<template>
    <div class="calculateItemOne">
      <h3>当天的涨跌幅风险</h3>
      <histogramFund v-if="index_list.length > 0" ref="zjlrsj" :thame="''" :name="'_zjlrsj'" :link="''" :title="title4"
        :listData="index_list" :timeData="index_time" :markLine="index_markline" :markPoint="index_markpoint"
        :areaStyle="areaStyle2" :legend1="legend1" :width1="'1400px'" :height1="'600px'" value=""></histogramFund>
  
    </div>
  </template>
  <script>
  import btnStausGroup from "../../../../../components/polyline/btnStausGroup.vue"
  import histogramFund from "../../histogramFund.vue"
  import {
    dealData
  } from "../../getUrl"
  import gridData from "../../js/gridData.js"
  import {
    setMarkLine
  } from "../../setMarkLine.js"
  //获取每个版块买入信息
  import initCaculate from "../../js/calculateStopLoss"
  import {
    initZhiDie,
    initMaxMinSpj,
  } from "../decrease/decreasePoint.js"
  //处理point
  import {
    dealPoint
  } from "../../common/util.js"
  export default {
    data() {
      return {
        title4: "",
        index_list: [],
        index_time: [],
        index_markline: [],
        index_markpoint: [],
        //第二个
        indexfun1: null,
        areaStyle2: [{}],
        btndataList: [],
        funData: [],
        inflowArray: [],
        calculateStopLoss: null,
        zhidie_array: [],
        legend1: undefined,
        zhidie_point: null,
        //输入的
        //当前个股的
        this_kline_data: null,
        //设置
       
      }
    },
    created() { },
    props: {
      day_data_array: {
        type: Object,
        default: null,
      },
    },
    components: {
      histogramFund,
      btnStausGroup,
    },
    created() {
      this.initData()
    },
    mounted() {
    },
    watch: {},
    methods: {
    
      // 搜索问题，处理 问题
        dealLineData(this_time, type2) {
          let that = this
          //处理数据
          let select_data = that.index_list;
          if (select_data.length == 0) return false;
          that.index_list = []
          let max_data = JSON.parse(JSON.stringify(select_data[0].num))
          let max_num = max_data.slice(this_time - 6, this_time)
          let num1 = this.calculateStopLoss.deal_data2.ji_zhidie.reverse()
          //缺少最大值= 
          let zdf_num_max = this.calculateStopLoss.deal_data2.zbs_array[this_time]
          let zdf_num_min = this.calculateStopLoss.deal_data2.ji_zhidie[this_time]
          // console.log("zdf_num_max==还是需要计算40天的数据", zdf_num_max);
          let gridData2 = gridData.dealMarkLine(
            that.indexfun1.num,
            select_data[0].num[this_time],
            zdf_num_max,
            zdf_num_min
          )
  
          let index_markline = setMarkLine(
            [
              gridData2.top_data5,
              {
                name: "当前的位置",
                num: select_data[0].num[this_time],
                time: that.index_time[this_time]
              },
              gridData2.bottom_data5,
            ],
            that.index_time
          )
          setTimeout(() => {
            that.index_list = select_data
            that.index_markline = index_markline
  
            if (type2 == 2) {
  
              let point2 = [{
                name: "买卖操作",
                value: "买入位置2",
                xAxis: that.index_time[this_time],
                yAxis: select_data[0].num[this_time],
              },]
  
              that.index_markpoint = [{
                data: point2,
              },
              {
                data: this.zhidie_point,
              },
              {},
              {},
              {},
              ]
            }
          }, 1000)
        },

        //处理返回来的数据
        dealStausPoint(deal_data) {
          let that = this
          //处理数据
          let select_data = that.index_list
          that.index_list = [];
          setTimeout(() => {
            that.index_list = select_data
            that.index_markpoint = deal_data
          }, 1000)
        },


       
        toFixedToolIndex(){
          this.$router.push({path:'/fixedToolIndex'});
        },
        initData() {
          const { day_data_array } = this;
          const that = this;
       
          // 基础数据初始化
          [that.indexfun1, that.this_kline_data] = [day_data_array, day_data_array];
          console.log("核心计算逻辑11", that.indexfun1);
          // 核心计算逻辑
          const calculateStopLoss = this.calculateStopLoss = initCaculate.calculateStopLoss2(
            [{ klines: this.indexfun1.all_klines?this.indexfun1.all_klines:this.indexfun1.klines}],
            this.indexfun1.all_klines?this.indexfun1.all_klines:this.indexfun1.klines,
            null,
            "",
            this.indexfun1.time
          );
         
          // 指数列表配置
          const indexListConfigs = [
            { num: that.indexfun1.num, name: that.indexfun1.name },
            { num: calculateStopLoss.deal_data2.ji_zhidie.reverse(), name: "止损跌幅" },
            { num: calculateStopLoss.deal_data2.zdf_min_array.reverse(), name: "20天最小值的幅度" },
            { num: calculateStopLoss.deal_data2.zdf_max_array.reverse(), name: "20天最大值的幅度" },
            { num: that.indexfun1.array, name: "每日涨跌", type_echarts: "bar", itemStyle: 2 },
            // { num: calculateStopLoss.max_spj_array, name: "最高值收盘价" },
            // { num: calculateStopLoss.spj_min_array, name: "收盘价最低价" },
            { num: calculateStopLoss.spj_max_min_array, name: "收盘价最高值最低价" },
            // { num: that.indexfun1.atr_klines, name: '波动率值' },
            { num: that.indexfun1.adjustedGrid, name: '网格间隔' },
          ];
          indexListConfigs.forEach(config => that.index_list.push(config));
          // 特殊数据处理
          this.zhidie_array = calculateStopLoss.deal_data2.ji_zhidie.reverse();
         // this.newAccumulative();
       //   const array1_item = [0, ...dealData(that.indexfun1.all_klines, 2, "成交额(亿)", 6).num];
          // 图例配置
          that.legend1={
            selected: { this_name: true, 止损跌幅: true, "20天最小值的幅度": false, "20天最大值的幅度": false }
          }
          // 可视化相关配置
          this.zhidie_point = dealPoint(initZhiDie(calculateStopLoss).zhidie_array.num, 0);
          [that.index_time, this.inflowArray] = [that.indexfun1.time, that.indexfun1.array];
          // 功能数据映射
          this.funData = this.index_list.slice(0, 5).map(item => item.num);
          // 按钮配置
          const [btnStates, btnColors] = [[1, 3, 3, 3, 2], ["#4992ff", "#7cffb2", "#fddd60", "#ff6e76", "#ff6e76"]];
          this.btndataList = this.index_list.slice(0, 5).map((item, index) => ({
            name: item.name,
            state: btnStates[index],
            color: btnColors[index]
          }));
          const point_spj_max_min = dealPoint(initMaxMinSpj(calculateStopLoss).zhidie_array.num, 0);
          that.index_markpoint=[{},{ data: this.zhidie_point }, {}, {}, { data: point_spj_max_min }]
       
      
        }, 
     
    },
   
  }
  </script>